import Mock from 'mockjs2'
import { builder } from '../util'

const totalCount = 5701

const status = [
  0,
  1,
  2
]

const status2 = [
  0,
  1
]

const yy = [
  '-',
  '-',
  '信息不全'
]

const checkList = () => {
  const result = []
  const pageNo = 0
  const pageSize = 15
  const totalPage = Math.ceil(totalCount / pageSize)
  const next = (pageNo >= totalPage ? (totalCount % pageSize) : pageSize) + 1
  for (let i = 1; i < next; i++) {
    result.push({
      id: Mock.mock('@id'),
      leader: Mock.mock('@cname'),
      member_name: Mock.mock('@cname'),
      submit_time: Mock.mock('@datetime'),
      status: status[i % 3],
      yy: yy[i % 3]
    })
  }

  return builder({
    pageSize: pageSize,
    pageNo: pageNo,
    totalCount: totalCount,
    totalPage: totalPage,
    data: result
  })
}

const settingList = () => {
  const result = []
  const pageNo = 0
  const pageSize = 15
  const totalPage = Math.ceil(totalCount / pageSize)
  const next = (pageNo >= totalPage ? (totalCount % pageSize) : pageSize) + 1
  for (let i = 1; i < next; i++) {
    result.push({
      id: Mock.mock('@id'),
      member_name: Mock.mock('@cname'),
      group_role: Mock.mock('@cname'),
      egis_at: Mock.mock('@datetime'),
      status: status2[i % 2],
      resource_daily_num_limit: Mock.mock('@integer(1,99)'),
      target_currmonth_yj: Mock.mock('@integer(3000,15000)'),
      target_dacall_sc: Mock.mock('@integer(10,300)')
    })
  }

  return builder({
    pageSize: pageSize,
    pageNo: pageNo,
    totalCount: totalCount,
    totalPage: totalPage,
    data: result
  })
}

const wxList = () => {
  const result = []
  const pageNo = 0
  const pageSize = 30
  const totalPage = Math.ceil(totalCount / pageSize)
  const next = (pageNo >= totalPage ? (totalCount % pageSize) : pageSize) + 1

  for (let i = 1; i < next; i++) {
    result.push({
      id: Mock.mock('@id'),
      adviser_name: Mock.mock('@cname'),
      add_time: Mock.mock('@datetime'),
      wx_id: Mock.mock('@String(11)'),
      image: 'http://upload.chtmxp.cn/20191202/1575270054938.jpg'
    })
  }

  return builder({
    pageSize: pageSize,
    pageNo: pageNo,
    totalCount: totalCount,
    totalPage: totalPage,
    data: result
  })
}

Mock.mock(/\/check/, 'get', checkList)
Mock.mock(/\/setting/, 'get', settingList)
Mock.mock(/\/weixin/, 'get', wxList)
